import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lib_core/customization/flutter/cupertino/text_selection.dart';
import 'package:lib_uikit/dimen/gt_dimensions_v3.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/widgets/gt_dropdown_v3.dart';

class GTTextDropdownWidgetV3 extends StatefulWidget {
  final String text;
  final Color? textColor;
  final double? paddingHorizontal;
  final double? paddingVertical;
  final bool? showStroke;
  final String? imagePath;
  final GTDropdownSizeV3? size;
  final bool? linearArrow; //线性箭头
  final bool? popupShowing;
  final bool? textFieldType;
  const GTTextDropdownWidgetV3({
    super.key,
    required this.text,
    this.textColor,
    this.size,
    this.paddingVertical,
    this.paddingHorizontal,
    this.showStroke,
    this.imagePath,
    this.linearArrow = false,
    this.popupShowing,
    this.textFieldType,
  });

  @override
  State<StatefulWidget> createState() => _DropdownTextWidgetV3();
}

class _DropdownTextWidgetV3 extends State<GTTextDropdownWidgetV3> {
  late bool _showStroke;
  int type = 0; //0币种dropdown，1实心箭头Text类型dropdown，2线性箭头Text类型dropdown
  late TextStyle textStyle;
  late double textSize,iconSize,arrowSize;
  double space = 4;
  @override
  void initState() {
    super.initState();
     _showStroke = widget.showStroke ?? false;
    if (widget.textFieldType ?? false) {
      textStyle = gtTextStyleW400();
      arrowSize = 20;
    }
    if ((widget.imagePath ?? "").isEmpty) {
      if (widget.linearArrow ?? false) {
        type = 2;
        space = 2;
      } else {
        type = 1;
        space = 0;
      }
    }
    switch (widget.size??GTDropdownSizeV3.size24) {
      case GTDropdownSizeV3.size24:
        if (type == 0 || type == 1) {
          textStyle = gtTextStyleW700();
        } else {
          textStyle = gtTextStyleW500();
        }
        iconSize = 24;
        textSize = 16;
        arrowSize = 16;
        break;
      case GTDropdownSizeV3.size20:
        iconSize = 20;
        textStyle = gtTextStyleW500();
        textSize = 14;
        arrowSize = 16;
        break;
      case GTDropdownSizeV3.size16:
        if (type == 0) {
          textStyle = gtTextStyleW500();
        } else {
          textStyle = gtTextStyleW400();
        }
        iconSize = 16;
        textSize = 14;
        arrowSize = 12;
        break;
      case GTDropdownSizeV3.size15:
        if (type == 0 || type == 1) {
          textStyle = gtTextStyleW500();
        } else {
          textStyle = gtTextStyleW400();
        }
        iconSize = 15;
        textSize = 13;
        arrowSize = 14;
        break;
      case GTDropdownSizeV3.size14:
        if (type == 0 || type == 1) {
          textStyle = gtTextStyleW500();
        } else {
          textStyle = gtTextStyleW400();
        }
        iconSize = 14;
        textSize = 12;
        arrowSize = 12;
        break;
    }

  }

  @override
  Widget build(BuildContext context) {
    return
      Container(
        padding: EdgeInsets.symmetric(
          horizontal: widget.paddingHorizontal ?? 0,
          vertical: widget.paddingVertical ?? 0,
        ),
        decoration: BoxDecoration(
          border: Border.all(
            color: _showStroke ? GTColorsV3.divider5.color : Colors.transparent,
            width: _showStroke ? 1 : 0,
          ),
          borderRadius: BorderRadius.circular(3),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: [
            if (widget.imagePath != null) ...[
              GTImage(
                url: widget.imagePath ?? "",
                width: iconSize,
                height: iconSize,
                radiusAll: iconSize / 2,
                fit: BoxFit.cover,
                showPlaceholder: true,
              ),
              const SizedBox(
                width: 4,
              ),
            ],
            Text(
              widget.text,
              style: textStyle.copyWith(fontSize: textSize, color: widget.textColor ?? GTColorsV3.text1.color),
            ),
            SizedBox(
              width: space,
            ),
            if (widget.linearArrow ?? false) ...[
              //线性三角箭头icon
              Icon(
                widget.popupShowing??false ? GTIconFont.e8c9 : GTIconFont.e8c8,
                size: arrowSize,
                color: widget.popupShowing??false ? GTColorsV3.icon5.color : GTColorsV3.icon1.color,
              ),
            ] else ...[
              //实心三角箭头icon
              Icon(
                widget.popupShowing??false ? GTIconFont.e9f8 : GTIconFont.e9f7,
                size: arrowSize,
                color: widget.popupShowing??false ? GTColorsV3.icon5.color : GTColorsV3.icon1.color,
              ),
            ]
          ],
        ),
      );
  }
}
